package com.ocom.payhandle.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.card.EntityXfDeviceInfo;
import com.ocom.common.enums.DataSourceEnum;
import com.ocom.common.enums.MasterSlaveEnum;
import com.ocom.mysql.aspect.DataSourceAspect;
import com.ocom.payhandle.dao.IDaoXfDeviceInfo;
import com.ocom.payhandle.service.XfDeviceInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class XfDeviceInfoServiceImpl extends ServiceImpl<IDaoXfDeviceInfo, EntityXfDeviceInfo> implements XfDeviceInfoService {

	@Autowired
	private IDaoXfDeviceInfo xfDeviceInfo;


	@DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "companyId")
	@Override
	public EntityXfDeviceInfo selectPointId(Long companyId, String machNo) {
		QueryWrapper<EntityXfDeviceInfo> wrapper=new QueryWrapper();
		wrapper.select("fkpara_jobid","point_id");
		wrapper.eq("com_id",companyId);
		wrapper.eq("device_no",machNo);
		return xfDeviceInfo.selectOne(wrapper);
	}

	@DataSourceAspect(type= DataSourceEnum.PART_DB,companyId = "companyId")
	@Override
	public Boolean updateJobId(Long companyId, String machNo, String jobId) {
		UpdateWrapper<EntityXfDeviceInfo> updateWrapper=new UpdateWrapper<>();
		updateWrapper.set("fkpara_state",0);
		updateWrapper.eq("com_id",companyId);
		updateWrapper.eq("device_no",machNo);
		updateWrapper.eq("fkpara_jobid",jobId);
		return this.update(updateWrapper);
	}


	@DataSourceAspect(type = DataSourceEnum.PART_DB,companyId = "companyId")
	@Override
	public EntityXfDeviceInfo getParaJobid(Long companyId, String machNo) {
		QueryWrapper<EntityXfDeviceInfo> query = Wrappers.query();
		query.eq("com_id",companyId);
		query.eq("device_no",machNo);
		query.select("rsa_jobid");
		return xfDeviceInfo.selectOne(query);
	}

	@DataSourceAspect(type = DataSourceEnum.PART_DB,isMaster = MasterSlaveEnum.MASTER)
	@Override
	public Boolean updateRsa(Long companyId, String machNo, String jobId) {
		UpdateWrapper<EntityXfDeviceInfo> updateWrapper=new UpdateWrapper<>();
		updateWrapper.set("rsa_state",0);
		updateWrapper.eq("com_id",companyId);
		updateWrapper.eq("device_no",machNo);
		updateWrapper.eq("rsa_jobid",jobId);
		return this.update(updateWrapper);
	}


}
